﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using DapperExtensions;
using Dapper测试.Model;

namespace Dapper测试
{
    class Program
    {
        static void Main(string[] args)
        {
            string connString = ConfigurationManager.ConnectionStrings["PMSData"].ToString();

            using (IDbConnection conn = new SqlConnection(connString))
            {
                //conn.Execute(
                //    "INSERT INTO dbo.PersonPhone ( Name , Phone , PhoneType , IsDefault , CreateTime ) VALUES (@Name , @Phone , @PhoneType , @IsDefault , GETDATE() )",
                //    new { Name = "张三", Phone = "18931608223", PhoneType = 1, IsDefault = 1 });
                //var result = conn.Query<PersonPhone>("Select Id,CreateTime from PersonPhone where Id<@Id", new { Id = 2 });
                //BaseUser user = new BaseUser() { Name = "李思思", Sex = "女", CreateTime = DateTime.Now };
                //conn.Insert(user);

                //BaseUser user = conn.QueryFirstOrDefault<BaseUser>("Select * from BaseUser where Id=@Id", new { Id = 0 });
                //Dictionary<string, object> param = new Dictionary<string, object>();
                //StringBuilder sb = new StringBuilder();
                //////param.Add("Id", 1);
                ////param.Add("Title", "%" + "性" + "%");
                //Hashtable ht = new Hashtable
                //{
                //    //ht.Add("Title", "性");
                //    { "@Ids", new int[] { 1, 2, 3, 4 } }
                //};
                //GetStrWhereAndParam(ht, sb, param);
                //string strSql = "Select * from BaseDict where 1=1 " + sb;
                //BaseDict dict = conn.QueryFirstOrDefault<BaseDict>(strSql, new { Ids = new int[] { 1, 2, 3, 4 }.ToList() });

                //dict.IsLeaf = 1;
                //int ok = Edit(dict);

                //Console.ReadKey();

                int a = 4;
                Console.WriteLine(Convert.ToString(a,2));

                Console.ReadKey();
            }
        }

        public static int Edit(BaseDict user)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("update BaseDict set ");
            strSql.Append("Title=@Title,");
            strSql.Append("Sym=@Sym,");
            strSql.Append("Value=@Value,");
            strSql.Append("Remark=@Remark,");
            strSql.Append("ParentId=@ParentId,");
            strSql.Append("ParentName=@ParentName,");
            strSql.Append("Path=@Path,");
            strSql.Append("PathName=@PathName,");
            strSql.Append("Enable=@Enable,");
            strSql.Append("IsDel=@IsDel,");
            strSql.Append("CreateBy=@CreateBy,");
            strSql.Append("CreateDate=@CreateDate,");
            strSql.Append("ModifyBy=@ModifyBy,");
            strSql.Append("ModifyDate=@ModifyDate,");
            strSql.Append("DeleteBy=@DeleteBy,");
            strSql.Append("DeleteDate=@DeleteDate");
            strSql.Append(" where Id=@Id");
            using (IDbConnection DbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["PMSData"].ToString()))
            {
                return DbConn.Execute(strSql.ToString(), user);
            }

        }

        public static void GetStrWhereAndParam(Hashtable ht, StringBuilder sb, Dictionary<string, object> param)
        {
            //sb.Append(" And Title Like @Title");
            //param.Add("Title", "%" + ht["Title"] + "%");
            sb.Append(" And Id in @Ids");
            param.Add("Ids", ht["Ids"]);
        }



        
    }
}
